<?php
	require_once 'IOBase.php';

	class Relatorys extends IOBase
	{
		public function __construct()
		{
			//seta o nome da tabela
			parent::__construct('relatorys');
			//seta como uma aplicação zend framework
			$this->setZF(true);
		}

		//pega todas as formas de relatório
		public function getAll()
		{
			return $this->ioGet();
		}

		public function getResult($tableName,$columnName,$relatoryName)
		{
			if(isset($tableName) && isset($columnName) && isset($relatoryName))
			{
				$this->setTableName($tableName);
				$columArray = $this->getColumn($columnName);

				if($relatoryName == 'soma')
				{
					$result = 0;
					foreach($columArray as $elem => $value)
					{
						$result+= (int) $value;
					}

				}else if($relatoryName == 'media')
				{
					$result = 0;
					foreach($columArray as $elem => $value)
					{
						$result+= (int) $value;
					}

					$result = $result / sizeof($columArray);
				}
				elseif($relatoryName == 'contagem')
				{
					$result = sizeof($columArray);
				}

				return $result;				
			}	
			else
			{
				return false;
			}
		}

		private function getColumn($columnName)
		{
			if(isset($columnName))
			{
				$newArray = array();
				$result = $this->ioGet();
				foreach($result as $id => $value)
				{
					$newArray[$id] = $value[$columnName];
				}
				return $newArray;
			}
			return false;
		}

	}
?>